<template>
  <div class="shopcar-container">
    <van-swipe-cell>
      <div class="shopcart-box" v-for="(item, index) in carList" :key="index">
        <van-checkbox v-model="checked" checked-color="#F63515"></van-checkbox>
        <img :src="item.imageHost + item.mainImage" />
        <div class="shopcart-item-info">
          <p class="shopcart-name">
            {{ item.name }}
          </p>
          <p class="shopcart-subtitle">{{ item.subtitle }}</p>
          <div class="shopcart-stepper">
            <span class="shopcart-price">￥{{ item.price }}</span>
            <van-stepper v-model="value" min="5" max="8" />
          </div>
        </div>
      </div>
      <template slot="right">
        <van-button square type="danger" text="删除" />
      </template>
    </van-swipe-cell>
  
  </div>
</template>

<script>
import { getCartList } from "@/api";
export default {
  data() {
    return {
      checked: false,
      value: 1,
      carList: [], // 存储购物车数据
    };
  },
  methods: {
    fetchCarList() {
      getCartList((res) => {
        console.log(res);
        this.carList = res.data;
      });
    },
  },
  created() {
    this.fetchCarList();
  },
};
</script>

<style>
* {
  margin: 0;
  padding: 0;
}
.shopcar-container .shopcart-box {
  display: flex;
  justify-content: space-around;
  background: #fff;
  padding: 10px;
  margin: 10px 0;
  height: 200px;
}
.shopcar-container .shopcart-box img {
  width: 180px;
  height: 180px;
  margin: 0 10px;
}
.shopcart-item-info {
  display: flex;
  flex: 70%;
  flex-direction: column;
  justify-content: space-between;
}
.shopcart-name {
  height: 70px;
  font-size: 26px;
  overflow: hidden;
}

.shopcart-subtitle {
  font-size: 24px;
  color: #999;
}
.shopcart-stepper {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.shopcart-price {
  font-size: 30px;
  color: red;
}

.van-button {
  height: 200px;
}
</style>